package com.lipy.java8study.thread;

import com.lipy.java8study.Tools;

import javax.swing.plaf.TableHeaderUI;

/**
 * @description:
 * @author: lipy
 * @create: 2020-07-20 17:47
 **/

public class ObjectLockTest {
    public static class Lock{
        boolean result = true;

        public boolean isResult() {
            return result;
        }

        public void setResult(boolean result) {
            this.result = result;
        }
    }

    public static void main(String[] args) {
        Runnable run = () -> {
            System.out.println(123);
        };
        System.out.println(101);
        new Thread(run).start();

        Lock lock = new Lock();
        Lock lock2 = new Lock();
        System.out.println(lock == lock2);
//        new Thread(()->{
//            Tools.sleepMS(300);
//            lock.setResult(false);
//            System.out.println();
//        }).start();
        for (int i = 0; i < 9; i++) {
            new Thread(()->{
                System.out.println("start---"+Thread.currentThread().getName()+" "+lock.isResult());
                Tools.sleepMS(800);
                System.out.println(lock.isResult());
            }).start();
        }
        lock.setResult(false);
        System.out.println("main--");
    }


}
